package ui.fragment.company;

import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.trek2000.android.enterprise.Enterprise;
import com.trek2000.android.enterprise.R;

import java.util.ArrayList;

import adapter.company.AllCompanyFeedAdapter;
import adapter.company.CompanyFeedAdapter;
import controller.company.CompanyFeedAsync;
import model.AllCompanyFeedItem;
import ui.activity.login.Login;
import ui.fragment.drawer.NavigationDrawerFragment;

public class CompanyFeedFragment extends Fragment
        implements View.OnClickListener{

    /**
     * String section
     */
    /**
     * View section
     */

    public static ListView mLvInCompanyFeedFragment;
    public static CompanyFeedAdapter companyFeedAdapter = null;
    /**
     * Others section
     */

    /**
     * Listener section
     */

    public static Fragment newInstance() {
        CompanyFeedFragment fragment = new CompanyFeedFragment();
        return fragment;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {

        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View v = getLayoutInflater(savedInstanceState).inflate(
                R.layout.fragment_company_feed, container, false);
        // Initial views
        initialViews(v);
        initialData();
        setDataForCompanyFeedFragment();
        return v;
    }

    /**
     * Initialize methods
     */
    private void initialData() {
        companyFeedAdapter = new CompanyFeedAdapter(getActivity(), R.layout.simple_list_item_company_feed, CompanyFeedAsync.mAlCompanyFeed);
        mLvInCompanyFeedFragment.setAdapter(companyFeedAdapter);
    }

    private void initialViews(View v) {
        mLvInCompanyFeedFragment = (ListView) v.findViewById(R.id.lv_in_company_feed_fragment);
    }

    /**
     * The others methods
     */
    private void setDataForCompanyFeedFragment () {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
            new CompanyFeedAsync(getActivity()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
                    String.valueOf(Login.user.getUserInfo().getUserGlobalId()),Login.user.getUserInfo().getAccessToken(),
                    String.valueOf(Enterprise.company.getCompaniesOfUserInfoSelected().getCompanyId()), getActivity().getString(R.string.feed),
                    String.valueOf(Enterprise.company.getCompaniesOfUserInfoSelected().getUserCompanyId()),
                    "0");
        else
            new CompanyFeedAsync(getActivity()).execute(
                    String.valueOf(Login.user.getUserInfo().getUserGlobalId()),Login.user.getUserInfo().getAccessToken(),
                    String.valueOf(Enterprise.company.getCompaniesOfUserInfoSelected().getCompanyId()), getActivity().getString(R.string.feed),
                    String.valueOf(Enterprise.company.getCompaniesOfUserInfoSelected().getUserCompanyId()),
                    "0");
    }
}
